package com.ls.utils.pay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;


import org.springframework.stereotype.Component;

@Component
public class AlipayUtils {
    static String app_id = "2021004100632887";
    public static String charset = "utf8";
    public static String signType = "RSA2";
    //应用公钥
    public static String alipaypublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx2wNXCiwpG5r47V/qijZ7eFck/sqmFVX92gWln2ZZLKPJs/eqw5Oj+Sntsq8ZR564vvmFgnJHF0Ve5CpVqQUQvgDXM1dtgkFoBmMKvcwTlqCMBE+9f1utPJOjXvmOQ+goOIQrAspwVmMEDY+cVV0fOK2zlM0tZHaJmOUhRrc/Znh1+IQvO6VPiIWktlmxIMRNf12ICvK7HzUx9oMBxwao7AWQvb9zulYdbl2GVsedLetYi/ywa1Ha4naOC5JDX3Ca/G5tshKLlbaCrzZf0S9butlL2qXVLsJGkUaw9nnJJaa0D9lOMyOHGVrA+SUXLlewv4wfY6pW+z9R+7tEormFQIDAQAB";
    //应用私钥yidiantong.xsdr.top_私钥
    static String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDHbA1cKLCkbmvjtX+qKNnt4VyT+yqYVVf3aBaWfZlkso8mz96rDk6P5Ke2yrxlHnri++YWCckcXRV7kKlWpBRC+ANczV22CQWgGYwq9zBOWoIwET71/W608k6Ne+Y5D6Cg4hCsCynBWYwQNj5xVXR84rbOUzS1kdomY5SFGtz9meHX4hC87pU+IhaS2WbEgxE1/XYgK8rsfNTH2gwHHBqjsBZC9v3O6Vh1uXYZWx50t61iL/LBrUdrido4LkkNfcJr8bm2yEouVtoKvNl/RL1u62UvapdUuwkaRRrD2ecklprQP2U4zI4cZWsD5JRcuV7C/jB9jqlb7P1H7u0SiuYVAgMBAAECggEBAJgXAkFtDvr48/OgcpMVwM85dt+tSJkRTZt0mPWBKMGxpJeXJV0T9jqrynUQPYppKpN+RcY9BFJLc5zfgSaA0Ksad4YJYhT44H9vvITwLLk1MeDy5i+5bvs1aU9iVPzjvD+26bwsb1X0s2uR0yGgaMzuIzlMIADyEYwBmj3BdRU7MhcY8VCyXaqGuT/i1ZlprJAyO9hFYnqjkdCOOrWNe29I7bTCzYYVd0C8TJaI35wlON0jMSVeCyhmDwXF6N3zzx/I2DZ0w2ZdtJXygNwiNIl2z0kg0FAmebRhxyumej4TwfaWrAaxBiXS9DrmkMcztiZ3I/FJhz26+BcTYlfbRGkCgYEA/c6FH1IZ328Zwa7BhsWbgV0oKuF8LmDDu1GNG6GiYOXvjh7gQAjouI79t8hRfJHqQI2g8B5wd39zxt0hhGFjVNz+epFT2RUJ3bG0Qo6U2VTnPGUZNxISesbynW5wJ9OiEgE34GJkMC07PaXsJbI2MPOcN36b5Be+9PM7vW44c5cCgYEAySU4eTBhzg0Lu9ECQ3CvVZy/92MwLRrGoQljsaznW9K6srSAccf+sSPxE1W7Y+1Jp8foSvcoce8h83UqoBUg2GG0N57rZGlO+nb4Y+SDGijFP78peC9ImAWYhImy22ltaOM6BwHgY07N7rpIUHApb/PidQY2vBd+6ukndxXS+TMCgYAMZ4KEFFwlWmW03JiiwJeoC+iBqAGMtrf6OLMfzZeFCtfZZ1LobkcJdhuaVtT8tJjxTLq34ZT3kigTaQ1RTf0v0ZkyXlXtvyR7TEsWEafes1KV1g8UbPKwQ3bqENK0b5h1LtAPTF+/JwbFLY3MDdiuLcnNwIdX730qtZSO3ostwwKBgQCPktTDlChLxn4YmrCt6LIOPuu7Ln6Fw3YCHkyd1xfxL/J5emOwU5vVXx1Fus0eH5KSgxuo3tBsus8WEwzQ5SPjr6HOjc3hh1WLa/4Sd1qpAm8A+HcmRUHg2SWrfQpAmPkyg/a4Z7t9xxMxEqBpYhYBxihfdYb+LRs3nCLCWr6ThwKBgQCYWboACR3QhzrSf5E9QMCtrnXluPdZ6kbvYGnWW596fEBrHHmJtVRTWrTxphrZaED+GcKrqCM0JmfmogPe+dRVv1NrRkEGa2ELsANhKNVEFs6r7fWeTodBrOBNjT0uA0Ri66WCKVyhsBoVr5Xzd5kpV+p/Ubgj1oiFqzAvODq9Ow==";
    //设置应用公钥证书路径 appCertPublicKey_2021004100632887
//    static String app_cert_path = "F:\\cloud\\工作室old\\common\\project\\医点通\\支付宝支付信息\\appCertPublicKey_2021002187603323.crt";
    static String app_cert_content = "-----BEGIN CERTIFICATE-----\n" +
            "MIIEtzCCA5+gAwIBAgIQICMGJsYH5npUOaX/BN7zbzANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE\n" +
            "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0\n" +
            "aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs\n" +
            "YXNzIDEgUjEwHhcNMjMwNjI2MTQxMzA4WhcNMjgwNjI0MTQxMzA4WjB/MQswCQYDVQQGEwJDTjEz\n" +
            "MDEGA1UECgwq5Zub5bed6bKc55Sf5aS65Lq656eR5oqA5pyJ6ZmQ6LSj5Lu75YWs5Y+4MQ8wDQYD\n" +
            "VQQLDAZBbGlwYXkxKjAoBgNVBAMMITIwODgyNDE5MzM4MTgxODQtMjAyMTAwNDEwMDYzMjg4NzCC\n" +
            "ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMdsDVwosKRua+O1f6oo2e3hXJP7KphVV/do\n" +
            "FpZ9mWSyjybP3qsOTo/kp7bKvGUeeuL75hYJyRxdFXuQqVakFEL4A1zNXbYJBaAZjCr3ME5agjAR\n" +
            "PvX9brTyTo175jkPoKDiEKwLKcFZjBA2PnFVdHzits5TNLWR2iZjlIUa3P2Z4dfiELzulT4iFpLZ\n" +
            "ZsSDETX9diAryux81MfaDAccGqOwFkL2/c7pWHW5dhlbHnS3rWIv8sGtR2uJ2jguSQ19wmvxubbI\n" +
            "Si5W2gq82X9EvW7rZS9ql1S7CRpFGsPZ5ySWmtA/ZTjMjhxlawPklFy5XsL+MH2OqVvs/Ufu7RKK\n" +
            "5hUCAwEAAaOCASkwggElMB8GA1UdIwQYMBaAFHEH4gRhFuTl8mXrMQ/J4PQ8mtWRMB0GA1UdDgQW\n" +
            "BBSPiI1JQgUA6AUHUEjikebwPb3xUTBABgNVHSAEOTA3MDUGB2CBHAFuAQEwKjAoBggrBgEFBQcC\n" +
            "ARYcaHR0cDovL2NhLmFsaXBheS5jb20vY3BzLnBkZjAOBgNVHQ8BAf8EBAMCBsAwLwYDVR0fBCgw\n" +
            "JjAkoCKgIIYeaHR0cDovL2NhLmFsaXBheS5jb20vY3JsNzguY3JsMGAGCCsGAQUFBwEBBFQwUjAo\n" +
            "BggrBgEFBQcwAoYcaHR0cDovL2NhLmFsaXBheS5jb20vY2E2LmNlcjAmBggrBgEFBQcwAYYaaHR0\n" +
            "cDovL2NhLmFsaXBheS5jb206ODM0MC8wDQYJKoZIhvcNAQELBQADggEBAKu1YziUrrBlwG7qVMb9\n" +
            "xwr4SpzvOCa0ely2ft0SL8mFFy/x44/AP5cJT3Dhe3c7KqUvwGYWoDswZvuo7HCsdK6AggoRdixq\n" +
            "vsNH3/0MNLKZaEAHAt+yblr557mRJDApr2P4+R3u/1LxenxLaZAoSHaqkQyQ5e00avUzgGdLk82H\n" +
            "cEvKKxaWVsY+dtSTCNrxTZWCEby2a7TFFTPuJCu/lYmA2sm5yiAkWITsVw1H0ZTJFXKju0smMDNU\n" +
            "zkzWj41WF2h9+8QvqCsivGBzrFFhlwMESRgvmNr9fQ+IFcF7bFDAc75BrjoZzOC6qgN+OemnNRMB\n" +
            "FgxUHQS0LwqQTi9d9H0=\n" +
            "-----END CERTIFICATE-----";
    //设置支付宝公钥证书路径 alipayCertPublicKey_RSA2
//    static String alipay_cert_path = "F:\\cloud\\工作室old\\common\\project\\医点通\\支付宝支付信息\\alipayCertPublicKey_RSA2.crt";
    static String alipay_cert_content = "-----BEGIN CERTIFICATE-----\n" +
            "MIIDuDCCAqCgAwIBAgIQICMGJiuADtnKwA7u1KaycTANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE\n" +
            "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0\n" +
            "aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs\n" +
            "YXNzIDIgUjEwHhcNMjMwNjI2MTQxMzA5WhcNMjgwNjI0MTQxMzA5WjCBmDELMAkGA1UEBhMCQ04x\n" +
            "MzAxBgNVBAoMKuWbm+W3nemynOeUn+WkuuS6uuenkeaKgOaciemZkOi0o+S7u+WFrOWPuDEPMA0G\n" +
            "A1UECwwGQWxpcGF5MUMwQQYDVQQDDDrmlK/ku5jlrp0o5Lit5Zu9Kee9kee7nOaKgOacr+aciemZ\n" +
            "kOWFrOWPuC0yMDg4MjQxOTMzODE4MTg0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" +
            "wmPo0KnXITRviYtCCeBewy24yuQekkSL0HLwBjZKZYQ9eAaFL/BY9vt0xMWNp/yiyJuh7D7cusiK\n" +
            "eObFVF9AU0FKGrkSAKsWEZHdcdlBkKpSFSFhXFc60wANb7gT7xwJu91jz1du8hrsIFgNZHut/QEH\n" +
            "9BbkBuAFGmiAYE0BWFe2MU9EI48s4YEUlncO9m6Zr5ZWIgp2QS5KjL33UmS5U1b9smqFeao19f1l\n" +
            "Bae76utLGIydruwDtc8QYy1En2oVzArDIEHU38bWcFi7JRKMB+uJXza5smLPJOqM4yRWmKZ1zE9+\n" +
            "uINPg561LTb9chJ5+c1bmi4IMO8RkqBOPsVkZQIDAQABoxIwEDAOBgNVHQ8BAf8EBAMCA/gwDQYJ\n" +
            "KoZIhvcNAQELBQADggEBADbSQ8TR8fHwoup6ijzG9cJdieTUbR7a0Fzg2wXUHj7yyNQEpF0pqZ+o\n" +
            "Y1ewEy1WKm1PI3uqwVPxhqmkjzGD4u3bOBWFp/XtcZ7YjPCENywmvEqDL0Sk6PHcLJVzwdQMpvyJ\n" +
            "QYiFerrL3KKR3lqGxEhlnVeh6Pq7LPMajCpzVwS0ohxqy6a0VUPI/xgHghi/M4iOm5iCEvkb6+y/\n" +
            "8rXt3n4H125BvgS8jxbkDVkVjx1xoGaer3r6zRuRZ7WfspZ+dyhKiRNl+k5JQZKv+67FgTHmNEV4\n" +
            "iW/nSNZiECIgCBXp6VZI+1JEBZ7jJXHSTFCD8SZpjDhhkhgOBPj/Wu334EQ=\n" +
            "-----END CERTIFICATE-----\n" +
            "-----BEGIN CERTIFICATE-----\n" +
            "MIIE4jCCAsqgAwIBAgIIYsSr5bKAMl8wDQYJKoZIhvcNAQELBQAwejELMAkGA1UEBhMCQ04xFjAU\n" +
            "BgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5MTEw\n" +
            "LwYDVQQDDChBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IFIxMB4XDTE4MDMy\n" +
            "MjE0MzQxNVoXDTM3MTEyNjE0MzQxNVowgYIxCzAJBgNVBAYTAkNOMRYwFAYDVQQKDA1BbnQgRmlu\n" +
            "YW5jaWFsMSAwHgYDVQQLDBdDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTE5MDcGA1UEAwwwQW50IEZp\n" +
            "bmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSBDbGFzcyAyIFIxMIIBIjANBgkqhkiG9w0B\n" +
            "AQEFAAOCAQ8AMIIBCgKCAQEAsLMfYaoRoPRbmDcAfXPCmKf43pWRN5yTXa/KJWO0l+mrgQvs89bA\n" +
            "NEvbDUxlkGwycwtwi5DgBuBgVhLliXu+R9CYgr2dXs8D8Hx/gsggDcyGPLmVrDOnL+dyeauheARZ\n" +
            "fA3du60fwEwwbGcVIpIxPa/4n3IS/ElxQa6DNgqxh8J9Xwh7qMGl0JK9+bALuxf7B541Gr4p0WEN\n" +
            "G8fhgjBV4w4ut9eQLOoa1eddOUSZcy46Z7allwowwgt7b5VFfx/P1iKJ3LzBMgkCK7GZ2kiLrL7R\n" +
            "iqV+h482J7hkJD+ardoc6LnrHO/hIZymDxok+VH9fVeUdQa29IZKrIDVj65THQIDAQABo2MwYTAf\n" +
            "BgNVHSMEGDAWgBRfdLQEwE8HWurlsdsio4dBspzhATAdBgNVHQ4EFgQUSqHkYINtUSAtDPnS8Xoy\n" +
            "oP9p7qEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQELBQADggIB\n" +
            "AIQ8TzFy4bVIVb8+WhHKCkKNPcJe2EZuIcqvRoi727lZTJOfYy/JzLtckyZYfEI8J0lasZ29wkTt\n" +
            "a1IjSo+a6XdhudU4ONVBrL70U8Kzntplw/6TBNbLFpp7taRALjUgbCOk4EoBMbeCL0GiYYsTS0mw\n" +
            "7xdySzmGQku4GTyqutIGPQwKxSj9iSFw1FCZqr4VP4tyXzMUgc52SzagA6i7AyLedd3tbS6lnR5B\n" +
            "L+W9Kx9hwT8L7WANAxQzv/jGldeuSLN8bsTxlOYlsdjmIGu/C9OWblPYGpjQQIRyvs4Cc/mNhrh+\n" +
            "14EQgwuemIIFDLOgcD+iISoN8CqegelNcJndFw1PDN6LkVoiHz9p7jzsge8RKay/QW6C03KNDpWZ\n" +
            "EUCgCUdfHfo8xKeR+LL1cfn24HKJmZt8L/aeRZwZ1jwePXFRVtiXELvgJuM/tJDIFj2KD337iV64\n" +
            "fWcKQ/ydDVGqfDZAdcU4hQdsrPWENwPTQPfVPq2NNLMyIH9+WKx9Ed6/WzeZmIy5ZWpX1TtTolo6\n" +
            "OJXQFeItMAjHxW/ZSZTok5IS3FuRhExturaInnzjYpx50a6kS34c5+c8hYq7sAtZ/CNLZmBnBCFD\n" +
            "aMQqT8xFZJ5uolUaSeXxg7JFY1QsYp5RKvj4SjFwCGKJ2+hPPe9UyyltxOidNtxjaknOCeBHytOr\n" +
            "-----END CERTIFICATE-----\n";
    //设置支付宝根证书路径 alipayRootCert
//    static String alipay_root_cert_path = "F:\\cloud\\工作室old\\common\\project\\医点通\\支付宝支付信息\\alipayRootCert.crt";
    static String alipay_root_cert_content = "-----BEGIN CERTIFICATE-----\n" +
            "MIIBszCCAVegAwIBAgIIaeL+wBcKxnswDAYIKoEcz1UBg3UFADAuMQswCQYDVQQG\n" +
            "EwJDTjEOMAwGA1UECgwFTlJDQUMxDzANBgNVBAMMBlJPT1RDQTAeFw0xMjA3MTQw\n" +
            "MzExNTlaFw00MjA3MDcwMzExNTlaMC4xCzAJBgNVBAYTAkNOMQ4wDAYDVQQKDAVO\n" +
            "UkNBQzEPMA0GA1UEAwwGUk9PVENBMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE\n" +
            "MPCca6pmgcchsTf2UnBeL9rtp4nw+itk1Kzrmbnqo05lUwkwlWK+4OIrtFdAqnRT\n" +
            "V7Q9v1htkv42TsIutzd126NdMFswHwYDVR0jBBgwFoAUTDKxl9kzG8SmBcHG5Yti\n" +
            "W/CXdlgwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFEwysZfZ\n" +
            "MxvEpgXBxuWLYlvwl3ZYMAwGCCqBHM9VAYN1BQADSAAwRQIgG1bSLeOXp3oB8H7b\n" +
            "53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI\n" +
            "pDoiVhsLwg==\n" +
            "-----END CERTIFICATE-----\n" +
            "\n" +
            "-----BEGIN CERTIFICATE-----\n" +
            "MIIF0zCCA7ugAwIBAgIIH8+hjWpIDREwDQYJKoZIhvcNAQELBQAwejELMAkGA1UE\n" +
            "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmlj\n" +
            "YXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChBbnQgRmluYW5jaWFsIENlcnRpZmlj\n" +
            "YXRpb24gQXV0aG9yaXR5IFIxMB4XDTE4MDMyMTEzNDg0MFoXDTM4MDIyODEzNDg0\n" +
            "MFowejELMAkGA1UEBhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNV\n" +
            "BAsMF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChBbnQgRmluYW5j\n" +
            "aWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IFIxMIICIjANBgkqhkiG9w0BAQEF\n" +
            "AAOCAg8AMIICCgKCAgEAtytTRcBNuur5h8xuxnlKJetT65cHGemGi8oD+beHFPTk\n" +
            "rUTlFt9Xn7fAVGo6QSsPb9uGLpUFGEdGmbsQ2q9cV4P89qkH04VzIPwT7AywJdt2\n" +
            "xAvMs+MgHFJzOYfL1QkdOOVO7NwKxH8IvlQgFabWomWk2Ei9WfUyxFjVO1LVh0Bp\n" +
            "dRBeWLMkdudx0tl3+21t1apnReFNQ5nfX29xeSxIhesaMHDZFViO/DXDNW2BcTs6\n" +
            "vSWKyJ4YIIIzStumD8K1xMsoaZBMDxg4itjWFaKRgNuPiIn4kjDY3kC66Sl/6yTl\n" +
            "YUz8AybbEsICZzssdZh7jcNb1VRfk79lgAprm/Ktl+mgrU1gaMGP1OE25JCbqli1\n" +
            "Pbw/BpPynyP9+XulE+2mxFwTYhKAwpDIDKuYsFUXuo8t261pCovI1CXFzAQM2w7H\n" +
            "DtA2nOXSW6q0jGDJ5+WauH+K8ZSvA6x4sFo4u0KNCx0ROTBpLif6GTngqo3sj+98\n" +
            "SZiMNLFMQoQkjkdN5Q5g9N6CFZPVZ6QpO0JcIc7S1le/g9z5iBKnifrKxy0TQjtG\n" +
            "PsDwc8ubPnRm/F82RReCoyNyx63indpgFfhN7+KxUIQ9cOwwTvemmor0A+ZQamRe\n" +
            "9LMuiEfEaWUDK+6O0Gl8lO571uI5onYdN1VIgOmwFbe+D8TcuzVjIZ/zvHrAGUcC\n" +
            "AwEAAaNdMFswCwYDVR0PBAQDAgEGMAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFF90\n" +
            "tATATwda6uWx2yKjh0GynOEBMB8GA1UdIwQYMBaAFF90tATATwda6uWx2yKjh0Gy\n" +
            "nOEBMA0GCSqGSIb3DQEBCwUAA4ICAQCVYaOtqOLIpsrEikE5lb+UARNSFJg6tpkf\n" +
            "tJ2U8QF/DejemEHx5IClQu6ajxjtu0Aie4/3UnIXop8nH/Q57l+Wyt9T7N2WPiNq\n" +
            "JSlYKYbJpPF8LXbuKYG3BTFTdOVFIeRe2NUyYh/xs6bXGr4WKTXb3qBmzR02FSy3\n" +
            "IODQw5Q6zpXj8prYqFHYsOvGCEc1CwJaSaYwRhTkFedJUxiyhyB5GQwoFfExCVHW\n" +
            "05ZFCAVYFldCJvUzfzrWubN6wX0DD2dwultgmldOn/W/n8at52mpPNvIdbZb2F41\n" +
            "T0YZeoWnCJrYXjq/32oc1cmifIHqySnyMnavi75DxPCdZsCOpSAT4j4lAQRGsfgI\n" +
            "kkLPGQieMfNNkMCKh7qjwdXAVtdqhf0RVtFILH3OyEodlk1HYXqX5iE5wlaKzDop\n" +
            "PKwf2Q3BErq1xChYGGVS+dEvyXc/2nIBlt7uLWKp4XFjqekKbaGaLJdjYP5b2s7N\n" +
            "1dM0MXQ/f8XoXKBkJNzEiM3hfsU6DOREgMc1DIsFKxfuMwX3EkVQM1If8ghb6x5Y\n" +
            "jXayv+NLbidOSzk4vl5QwngO/JYFMkoc6i9LNwEaEtR9PhnrdubxmrtM+RjfBm02\n" +
            "77q3dSWFESFQ4QxYWew4pHE0DpWbWy/iMIKQ6UZ5RLvB8GEcgt8ON7BBJeMc+Dyi\n" +
            "kT9qhqn+lw==\n" +
            "-----END CERTIFICATE-----\n" +
            "\n" +
            "-----BEGIN CERTIFICATE-----\n" +
            "MIICiDCCAgygAwIBAgIIQX76UsB/30owDAYIKoZIzj0EAwMFADB6MQswCQYDVQQG\n" +
            "EwJDTjEWMBQGA1UECgwNQW50IEZpbmFuY2lhbDEgMB4GA1UECwwXQ2VydGlmaWNh\n" +
            "dGlvbiBBdXRob3JpdHkxMTAvBgNVBAMMKEFudCBGaW5hbmNpYWwgQ2VydGlmaWNh\n" +
            "dGlvbiBBdXRob3JpdHkgRTEwHhcNMTkwNDI4MTYyMDQ0WhcNNDkwNDIwMTYyMDQ0\n" +
            "WjB6MQswCQYDVQQGEwJDTjEWMBQGA1UECgwNQW50IEZpbmFuY2lhbDEgMB4GA1UE\n" +
            "CwwXQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxMTAvBgNVBAMMKEFudCBGaW5hbmNp\n" +
            "YWwgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgRTEwdjAQBgcqhkjOPQIBBgUrgQQA\n" +
            "IgNiAASCCRa94QI0vR5Up9Yr9HEupz6hSoyjySYqo7v837KnmjveUIUNiuC9pWAU\n" +
            "WP3jwLX3HkzeiNdeg22a0IZPoSUCpasufiLAnfXh6NInLiWBrjLJXDSGaY7vaokt\n" +
            "rpZvAdmjXTBbMAsGA1UdDwQEAwIBBjAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBRZ\n" +
            "4ZTgDpksHL2qcpkFkxD2zVd16TAfBgNVHSMEGDAWgBRZ4ZTgDpksHL2qcpkFkxD2\n" +
            "zVd16TAMBggqhkjOPQQDAwUAA2gAMGUCMQD4IoqT2hTUn0jt7oXLdMJ8q4vLp6sg\n" +
            "wHfPiOr9gxreb+e6Oidwd2LDnC4OUqCWiF8CMAzwKs4SnDJYcMLf2vpkbuVE4dTH\n" +
            "Rglz+HGcTLWsFs4KxLsq7MuU+vJTBUeDJeDjdA==\n" +
            "-----END CERTIFICATE-----\n" +
            "\n" +
            "-----BEGIN CERTIFICATE-----\n" +
            "MIIDxTCCAq2gAwIBAgIUEMdk6dVgOEIS2cCP0Q43P90Ps5YwDQYJKoZIhvcNAQEF\n" +
            "BQAwajELMAkGA1UEBhMCQ04xEzARBgNVBAoMCmlUcnVzQ2hpbmExHDAaBgNVBAsM\n" +
            "E0NoaW5hIFRydXN0IE5ldHdvcmsxKDAmBgNVBAMMH2lUcnVzQ2hpbmEgQ2xhc3Mg\n" +
            "MiBSb290IENBIC0gRzMwHhcNMTMwNDE4MDkzNjU2WhcNMzMwNDE4MDkzNjU2WjBq\n" +
            "MQswCQYDVQQGEwJDTjETMBEGA1UECgwKaVRydXNDaGluYTEcMBoGA1UECwwTQ2hp\n" +
            "bmEgVHJ1c3QgTmV0d29yazEoMCYGA1UEAwwfaVRydXNDaGluYSBDbGFzcyAyIFJv\n" +
            "b3QgQ0EgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOPPShpV\n" +
            "nJbMqqCw6Bz1kehnoPst9pkr0V9idOwU2oyS47/HjJXk9Rd5a9xfwkPO88trUpz5\n" +
            "4GmmwspDXjVFu9L0eFaRuH3KMha1Ak01citbF7cQLJlS7XI+tpkTGHEY5pt3EsQg\n" +
            "wykfZl/A1jrnSkspMS997r2Gim54cwz+mTMgDRhZsKK/lbOeBPpWtcFizjXYCqhw\n" +
            "WktvQfZBYi6o4sHCshnOswi4yV1p+LuFcQ2ciYdWvULh1eZhLxHbGXyznYHi0dGN\n" +
            "z+I9H8aXxqAQfHVhbdHNzi77hCxFjOy+hHrGsyzjrd2swVQ2iUWP8BfEQqGLqM1g\n" +
            "KgWKYfcTGdbPB1MCAwEAAaNjMGEwHQYDVR0OBBYEFG/oAMxTVe7y0+408CTAK8hA\n" +
            "uTyRMB8GA1UdIwQYMBaAFG/oAMxTVe7y0+408CTAK8hAuTyRMA8GA1UdEwEB/wQF\n" +
            "MAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQBLnUTfW7hp\n" +
            "emMbuUGCk7RBswzOT83bDM6824EkUnf+X0iKS95SUNGeeSWK2o/3ALJo5hi7GZr3\n" +
            "U8eLaWAcYizfO99UXMRBPw5PRR+gXGEronGUugLpxsjuynoLQu8GQAeysSXKbN1I\n" +
            "UugDo9u8igJORYA+5ms0s5sCUySqbQ2R5z/GoceyI9LdxIVa1RjVX8pYOj8JFwtn\n" +
            "DJN3ftSFvNMYwRuILKuqUYSHc2GPYiHVflDh5nDymCMOQFcFG3WsEuB+EYQPFgIU\n" +
            "1DHmdZcz7Llx8UOZXX2JupWCYzK1XhJb+r4hK5ncf/w8qGtYlmyJpxk3hr1TfUJX\n" +
            "Yf4Zr0fJsGuv\n" +
            "-----END CERTIFICATE-----";

    public AlipayClient getAlipayClient() throws Exception {
//        if (TxtUtil.isEmpty(shop.getAppId())
//                || TxtUtil.isEmpty(shop.getPrivateKey())
//                || TxtUtil.isEmpty(shop.getAppCertContent())
//                || TxtUtil.isEmpty(shop.getAlipayCertPathContent())
//                || TxtUtil.isEmpty(shop.getAlipayRootCertPathContent())
//        ) {
//            throw new Exception("门店支付信息配置未完成");
//        }
        //构造client
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        //设置网关地址
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
        //设置应用Id
        certAlipayRequest.setAppId(app_id);
        //设置应用私钥
        certAlipayRequest.setPrivateKey(privateKey);
        //设置请求格式，固定值json
        certAlipayRequest.setFormat("json");
        //设置字符集
        certAlipayRequest.setCharset(charset);
        //设置签名类型
        certAlipayRequest.setSignType(signType);
        //设置应用公钥证书路径
//        certAlipayRequest.setCertPath(app_cert_path);
        certAlipayRequest.setCertContent(app_cert_content);
        //设置支付宝公钥证书路径
//        certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
        certAlipayRequest.setAlipayPublicCertContent(alipay_cert_content);
        //设置支付宝根证书路径
//        certAlipayRequest.setRootCertPath(alipay_root_cert_path);
        certAlipayRequest.setRootCertContent(alipay_root_cert_content);
        //构造client
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
        return alipayClient;
    }

    /**
     * 发起请求，直接返回orderinfo给前端使用无需再做任何更改
     */
    public String getPayOrderInfo(String title, String content, String amount, String outTradeNo) throws Exception {
        //构造client
        AlipayClient alipayClient = getAlipayClient();
        if (alipayClient == null) {
            throw new Exception("门店支付配置文件异常");
        }
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();

        //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody(title);
        model.setSubject(content);
        model.setOutTradeNo(outTradeNo);
        model.setTimeoutExpress("30m");
        model.setTotalAmount(amount);
        model.setProductCode("QUICK_MSECURITY_PAY");
        request.setBizModel(model);
//        request.setNotifyUrl("https://yidiantong.xsdr.top/yidiantong/");
//        request.setNotifyUrl("http://frpyidiantong.luozisong.top/yidiantong/config/wechat/alipayNofity");

        //这里和普通的接口调用不同，使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
//            System.out.println(response.getBody()); //就是orderString 可以直接给客户端请求，无需再做处理。
        String orderInfo = response.getBody();

        return orderInfo;
    }

    /**
     * 是否已经支付了该订单
     */
    public boolean isPayOrder(String orderNum) throws Exception {
        //构造client
        AlipayClient alipayClient = getAlipayClient();
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", orderNum);
        //bizContent.put("trade_no", "2014112611001004680073956707");
        request.setBizContent(bizContent.toString());
        AlipayTradeQueryResponse response = alipayClient.certificateExecute(request);
        if (response.isSuccess()) {
            System.out.println("调用成功");
            if ("TRADE_SUCCESS".equals(response.getTradeStatus())) {
                return true;
            } else {
                return false;
            }
        } else {
            System.out.println("调用失败");
            return false;
        }
    }

    /**
     * 请求提现
     *
     * @param withdrawNum  提现订单号，由开发者生成
     * @param account      提现的账号  手机号或邮箱
     * @param name         提现人的真实姓名
     * @param trans_amount 提现金额 最低0.1元
     * @param title        提现显示的标题-》转账备注
     * @param remark       备注、理由
     */
    public void requestWithdraw(String withdrawNum, String account, String name, String trans_amount, String title, String remark) throws Exception {
        if (TxtUtil.getDouble(trans_amount) < 0.1) {
            throw new Exception("最低提现金额0.1元");
        }
        //构造client
        AlipayClient alipayClient = getAlipayClient();

        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
        AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
        model.setOutBizNo(withdrawNum);
        model.setRemark(remark);
        model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
        model.setBizScene("DIRECT_TRANSFER");
        Participant payeeInfo = new Participant();
        payeeInfo.setIdentity(account);
        payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
        payeeInfo.setName(name);
        model.setPayeeInfo(payeeInfo);
        model.setTransAmount(trans_amount);
        model.setProductCode("TRANS_ACCOUNT_NO_PWD");
        model.setOrderTitle(title);
        request.setBizModel(model);

//        request.setBizContent("{" +
//                "\"out_biz_no\":" + withdrawNum + "," +
//                "\"trans_amount\":" + trans_amount + "," +
//                "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
//                "\"biz_scene\":\"DIRECT_TRANSFER\"," +
//                "\"order_title\":\"" + title + "\"," +
//                "\"payee_info\":{" +
//                "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
//                "\"identity\":\"" + account + "\"," +
//                "\"name\":\"" + name + "\"," +
//                "}," +
//                "\"remark\":\"" + remark + "\"," +
//                "\"business_params\":\"{\\\"payer_show_name\\\":\\\"提现\\\"}\"" +
//                "}");
        AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            throw new Exception(response.getSubMsg());
        }
    }

//    public static void main(String[] args) throws AlipayApiException {
//        //根据证书查询公钥
//        String publicKey = AlipaySignature.getAlipayPublicKey(app_cert_path);
//        //输出应用公钥的值
//        System.out.println("publicKey:" + publicKey);
//    }
}
